const {service} = require("../request");
const model = require("../../utils/modelUtil");

/**
 * 特殊事件
 */
class Special {
    constructor(user) {
        this.user = user;
    }

    /**
     * 检测
     * @param type 2=危虎山 3=老乞丐
     * @returns {Promise<unknown>}
     */
    check(type) {
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/checkSpecial',
                data: model.userModel('checkSpecial', {type: type}, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }

    /**
     * 获取奖励
     * @param type 2=危虎山 3=老乞丐
     * @returns {Promise<unknown>}
     */
    getReward(type) {
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/bringSpecialAward',
                data: model.userModel('bringSpecialAward', {flag: 1, type: type}, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }
}

module.exports = Special;